package com.meego.common.timer;

import java.util.Calendar;
import java.util.Date;

public class IntervalEvent extends TimedAdaptor {

    private Date mDate;
    private boolean mSingleShot;
    private int mHourIncr;
    private int mMinIncr;
    private int mSecIncr;

    public IntervalEvent(int hour, int min, int sec, boolean singleShot) {
        this.mDate = new Date();
        this.mHourIncr = hour;
        this.mMinIncr = min;
        this.mSecIncr = sec;
        this.mSingleShot = singleShot;
    }

    @Override
    public Date getNextEvent() {
        if (this.mDate == null) {
            return null;
        }

        Calendar cal = Calendar.getInstance();
        cal.setTime(this.mDate);
        cal.add(11, this.mHourIncr);
        cal.add(12, this.mMinIncr);
        cal.add(13, this.mSecIncr);
        this.mDate = cal.getTime();

        Date ret = this.mDate;

        if (this.mSingleShot) {
            this.mDate = null;
        }
        return ret;
    }
}